zabbix监控mongodb

        mongodb的监控,下面是部署过程:

        第一步,先在zabbix_agentd.conf中追加下面的内容,主要是调用mongo这个工具通过db.serverStatus()函数获取mongodb的状态,这里需要注意的是连接的IP和端口不能配置错误,最好是要检查一下mongodb的配置文件里面的IP和端口是否一致:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#monitor mongodb
UserParameter=mongo.service,ps -ef | grep mongo |grep -v grep |wc -l
UserParameter=mongo.mem_resident,echo "db.serverStatus().mem"|/data/mongodb/mongodb/bin/mongo 127.0.0.1:27017|grep resident | cut -d ":" -f 2 |cut -d "," -f 1| cut -d " " -f 2
UserParameter=mongo.mem_virtual,echo "db.serverStatus().mem"|/data/mongodb/mongodb/bin/mongo 127.0.0.1:27017|grep virtual | cut -d ":" -f 2 |cut -d "," -f 1| cut -d " " -f 2
UserParameter=mongo.mem_mapped,echo "db.serverStatus().mem"|/data/mongodb/mongodb/bin/mongo 127.0.0.1:27017|grep '\bmapped\b' | cut -d ":" -f 2 |cut -d "," -f 1| cut -d " " -f 2
UserParameter=mongo.network[*],echo "db.serverStatus().network"|/data/mongodb/mongodb/bin/mongo 127.0.0.1:27017| grep $1 | cut -d ":" -f 2 |cut -d "," -f1 |cut -d " " -f 2
UserParameter=mongo.index[*],echo "db.serverStatus().indexCounters"|/data/mongodb/mongodb/bin/mongo 127.0.0.1:27017| grep $1| cut -d ":" -f 2 |cut -d "," -f1 |cut -d " " -f 2
UserParameter=mongo.connection_current,echo "db.serverStatus().connections"|/data/mongodb/mongodb/bin/mongo 127.0.0.1:27017| grep current|cut -d ":" -f 2|cut -d "," -f 1|cut -d " " -f 2
UserParameter=mongo.connection_available,echo "db.serverStatus().connections"|/data/mongodb/mongodb/bin/mongo 127.0.0.1:27017| grep current| cut -d ":" -f 3|cut -d "," -f 1 |cut -d " " -f 2
UserParameter=mongo.opcounters[*],echo "db.serverStatus().opcounters" |/data/mongodb/mongodb/bin/mongo 127.0.0.1:27017| grep $1|cut -d ":" -f 2|cut -d "," -f 1 |cut -d " " -f 2
UserParameter=mongo.rpstatus,echo "rs.status()"|/data/mongodb/mongodb/bin/mongo 127.0.0.1:27017| grep myState| cut -d ":" -f 2| cut -d "," -f 1 |cut -d " " -f 2
UserParameter=mongo.queue_write,echo "db.serverStatus().globalLock.currentQueue.writers"|/data/mongodb/mongodb/bin/mongo 127.0.0.1:27017|sed -n 3p
UserParameter=mongo.queue_reader,echo "db.serverStatus().globalLock.currentQueue.readers"|/data/mongodb/mongodb/bin/mongo 127.0.0.1:27017|sed -n 3p
UserParameter=mongo.backgroundFlush,echo "db.serverStatus().backgroundFlushing.last_ms" |/data/mongodb/mongodb/bin/mongo 127.0.0.1:27017|sed -n 3p
UserParameter=mongo.curosor_Totalopen,echo "db.serverStatus().cursors.totalOpen" |/data/mongodb/mongodb/bin/mongo 127.0.0.1:27017|sed -n 3p
UserParameter=mongo.curospr_timedOu,echo "db.serverStatus().cursors.timedOut" |/data/mongodb/mongodb/bin/mongo 127.0.0.1:27017|sed -n 3p
UserParameter=mongo.pagefaults,echo "db.serverStatus().extra_info.page_faults" |/data/mongodb/mongodb/bin/mongo 127.0.0.1:27017|sed -n 3p
UserParameter=mongo.oplog_storetime,echo "db.printReplicationInfo()"|/data/mongodb/mongodb/bin/mongo 127.0.0.1:27017|sed -n 4p|cut -d "(" -f 2|cut -d "h" -f 1

        追加完成后重启zabbix_agentd然后在zabbix_server端使用zabbix_get尝试是否能够获取到数据,如果能获取到数据说明客户端已经配置好了,接下来配置服务端,将下面提供的模板导入,然后添加相应主机到模版中就行了。